import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/data_table.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/router/app_pages.dart';

import 'personnel_monitoring_controller.dart';

/// 人员检测
class PersonnelMonitoringPage extends StatelessWidget {
  PersonnelMonitoringPage({required this.tabCtrl, super.key});

  final TabController tabCtrl;

  final controller = Get.put(PersonnelMonitoringController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return controller.tableData.isNotEmpty
            ? SingleChildScrollView(
                physics: const ClampingScrollPhysics(),
                child: Container(
                  padding:
                      EdgeInsets.only(left: 16.w, right: 16.w, bottom: 20.w),
                  color: Colors.white,
                  child: Column(
                    children: [
                      DataTables(
                        controller.tableData,
                        onActionClick: (String row) {
                          Get.toNamed(Routes.dynamicTrajectoryPage, arguments: controller.tableDataS[int.parse(row)].id)?.then((_){
                            // 设置系统首选的方向为竖屏
                            SystemChrome.setPreferredOrientations([
                              DeviceOrientation.portraitUp,
                              DeviceOrientation.portraitDown,
                            ]);
                            SystemChrome.setEnabledSystemUIMode(
                              SystemUiMode.manual,
                              overlays: SystemUiOverlay.values,
                            );
                          });
                        },
                        onOverScroll: (noti) {
                          // if (noti is! ScrollUpdateNotification) return;
                          // if (noti.metrics.pixels < -70.w && tabCtrl.index == 2) {
                          //   tabCtrl.animateTo(1, duration: Durations.long4);
                          // }
                        },
                      ),
                      AppGaps.vGap50,
                    ],
                  ),
                ),
              )
            : Container(
                color: Colors.white,
                child: Center(
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      SvgPicture.asset('assets/svg/zhiban_empty_bg.svg'),
                      Text(
                        '暂无内容',
                        style: TextStyle(
                          color: const Color(0xFFC7CEE5),
                          fontSize: 14.sp,
                        ),
                      ),
                      AppGaps.vGap20,
                    ],
                  ),
                ),
              );
      },
    );
  }
}
